package vip.liux.contracts.shared.value;

import java.util.List;

/**
 * 通用范围抽象（如日期范围、数值范围等）
 */
public interface DataRange<T> {
    /**
     * 快捷创建
     */
    static <T> DataRange<T> of(List<T> between) {
        return () -> between;
    }

    /**
     * 获取范围起点
     */
    default T getStart() {
        List<T> between = getBetween();
        return (between == null || between.isEmpty()) ? null : between.get(0);
    }

    /**
     * 获取范围终点
     */
    default T getEnd() {
        List<T> between = getBetween();
        return (between == null || between.isEmpty()) ? null : between.get(between.size() - 1);
    }

    /**
     * 原始范围值（如[开始, 结束]）
     */
    List<T> getBetween();

    /**
     * 范围是否合法（有起止值）
     */
    default boolean isValid() {
        List<T> between = getBetween();
        return between != null && between.size() >= 2;
    }

    /**
     * 范围长度
     */
    default int size() {
        List<T> between = getBetween();
        return between == null ? 0 : between.size();
    }

    /**
     * 是否为空
     */
    default boolean isEmpty() {
        List<T> between = getBetween();
        return between == null || between.isEmpty();
    }
}